<?php
/**
 * PHP Framework Artificial Intelligence Branches and Bounds Choice Tree class
 * This class is base for all classes which implement intellectual search
 * using the Branches and Bounds algorithm
 *
 * @author Andrew <andrew@vitche.com>
 * @author Frozen Rain <frozenrain@mail.ru>
 **/
abstract class BranchesBoundsChoiceTree extends ChoiceTree {

    /**
     * Checks whether the node can be expanded according
     * to the branches and bounds criterion
     *
     * Must be overriden to define the criterion
     * Can be not overriden to avoid using the criterion
     *
     * If not overriden the algorithm becomes the full-search algorithm
     *
     * @param mixed $node
     **/
    protected function canExpand(&$node) {

        return true;
    }

    /**
     * Expands the given node
     * The node being expanded is checked to fit the upper
     * and the lower mark condition
     * If it fits the condition the node is expanded
     * Otherwise it is ommitted
     *
     * @param mixed $node
     * @return array The list of child nodes
     **/
    protected function expand(&$node) {

        // The node can be expanded
        if ($this->canExpand($node)) {

            return $this->mutate($node);
        }

        // The node cannot be expanded
        return array();
    }

    /**
     * Builds the list of child nodes from the given node
     * Must be overriden to define the mutation scheme
     *
     * @param mixed $node
     * @return array The list of child nodes
     **/
    protected function mutate(&$node) {

        return array();
    }
}
?>